﻿<UserControl x:Class="WpfPdfReader.LabPdfReaderControl"
             xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
             xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
             xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006" 
             xmlns:d="http://schemas.microsoft.com/expression/blend/2008" 
             xmlns:local="clr-namespace:WpfPdfReader"
             mc:Ignorable="d" 
             d:DesignHeight="768" d:DesignWidth="1024" PreviewKeyDown="UserControl_PreviewKeyDown" Focusable="True" SizeChanged="UserControl_SizeChanged" AllowDrop="True" DragEnter="UserControl_DragEnter" Drop="UserControl_Drop">
    <UserControl.ContextMenu>

        <ContextMenu Name="contextMenu">
            <MenuItem  Header="(_O)打开PDF文件" Name="OpenPdf" Click="OpenPdf_Click">
                <MenuItem.Icon >
                    <Image Width="16" Height="16" Source="images/OpenFile.png"/>
                </MenuItem.Icon>
            </MenuItem>
        </ContextMenu>

    </UserControl.ContextMenu>
    <UserControl.Resources>
        <Storyboard x:Key="display">
            <DoubleAnimationUsingKeyFrames BeginTime="00:00:00" Storyboard.TargetName="border" Storyboard.TargetProperty="(UIElement.Opacity)">
                <SplineDoubleKeyFrame KeyTime="00:00:00" Value="0"/>
                <SplineDoubleKeyFrame KeyTime="00:00:00.4000000" Value="1"/>
            </DoubleAnimationUsingKeyFrames>
        </Storyboard>
        <Storyboard x:Key="hidden">
            <DoubleAnimationUsingKeyFrames BeginTime="00:00:00" Storyboard.TargetProperty="(UIElement.Opacity)" Storyboard.TargetName="border">
                <SplineDoubleKeyFrame KeyTime="00:00:00" Value="1"/>
                <SplineDoubleKeyFrame KeyTime="00:00:00.4000000" Value="0"/>
            </DoubleAnimationUsingKeyFrames>
        </Storyboard>

        <!--快捷键设置-->
        <RoutedUICommand x:Key="KZoomIn" Text="放大"/>
        <RoutedUICommand x:Key="KZoomOut" Text="缩小"/>
        <RoutedUICommand x:Key="KExportImage" Text="导出图片"/>
        <RoutedUICommand x:Key="KExportAllImage" Text="导出所有图片"/>
    </UserControl.Resources>

    <UserControl.InputBindings>
        <KeyBinding Gesture="Ctrl+Alt+F"  Command="{StaticResource KZoomIn}"/>
        <KeyBinding Gesture="Ctrl+Alt+D" Command="{StaticResource KZoomOut}"/>
        <KeyBinding Gesture="Ctrl+E" Command="{StaticResource KExportImage}"/>
        <KeyBinding Gesture="Ctrl+T" Command="{StaticResource KExportAllImage}"/>
    </UserControl.InputBindings>
    <UserControl.CommandBindings>
        <CommandBinding Command="{StaticResource KZoomIn}" x:Name="CZoomIn"  Executed="ZoomIn_Executed" CanExecute="CZoomIn_CanExecute"/>
        <CommandBinding Command="{StaticResource KZoomOut}" x:Name="CZoomOut"  Executed="ZoomOut_Executed" CanExecute="CZoomOut_CanExecute"/>
        <CommandBinding Command="{StaticResource KExportImage}" x:Name="CExportImage" Executed="CExportImage_Executed" CanExecute="CExportImage_CanExecute"/>
        <CommandBinding Command="{StaticResource KExportAllImage}" x:Name="CExportAllImage" Executed="CExportAllImage_Executed" CanExecute="CExportAllImage_CanExecute"/>
    </UserControl.CommandBindings>
    <UserControl.Triggers>
        <!--<EventTrigger RoutedEvent="Mouse.MouseEnter" SourceName="MasterScrollViewer">
                <BeginStoryboard Storyboard="{StaticResource display}"/>
            </EventTrigger>
            <EventTrigger RoutedEvent="Mouse.MouseLeave" SourceName="MasterScrollViewer">
                <BeginStoryboard Storyboard="{StaticResource hidden}"/>
            </EventTrigger>-->
    </UserControl.Triggers>
    <UserControl.FocusVisualStyle >
        <Style>
            <Setter Property="Control.Template">
                <Setter.Value>
                    <ControlTemplate>
                        <Rectangle Margin="-2" StrokeThickness="1" Stroke="Red" StrokeDashArray="0"/>
                    </ControlTemplate>
                </Setter.Value>
            </Setter>
        </Style>
    </UserControl.FocusVisualStyle>
    
    <Grid>
        <Rectangle Name="rectImage" Fill="{StaticResource winBackground}"/>
        <Grid Margin="{Binding ElementName=rectImage, Path=Margin}" >

            <Grid.RowDefinitions>
                <RowDefinition Height="*"/>
                <RowDefinition Height="50"/>
            </Grid.RowDefinitions>
            <Border Grid.Row="0" Background="Transparent" Margin="10,5,10,0" Name="imageBorder">
                <Border.Resources>
                    <TransformGroup x:Key="ImageTransformResource">
                        <ScaleTransform />
                        <TranslateTransform/>
                        <MatrixTransform/>
                    </TransformGroup>
                </Border.Resources>

                <ScrollViewer HorizontalScrollBarVisibility="Hidden" Cursor="Arrow" Focusable="True"
              VerticalScrollBarVisibility="Hidden" x:Name="MasterScrollViewer" Margin="3" Background="Transparent"
                              ScrollChanged="MasterScrollViewer_ScrollChanged" 
                              MouseEnter="MasterScrollViewer_MouseEnter" 
                              MouseLeave="MasterScrollViewer_MouseLeave">
                    <ContentControl Name="touchPad" MouseLeftButtonDown="MasterImage_MouseLeftButtonDown"
                   MouseLeftButtonUp="MasterImage_MouseLeftButtonUp"
                   MouseMove="MasterImage_MouseMove"
                   MouseWheel="MasterImage_MouseWheel"
                   ManipulationStarting="image_ManipulationStarting"  
                   ManipulationDelta="image_ManipulationDelta"
                   ManipulationCompleted="image_ManipulationCompleted"
                   ManipulationInertiaStarting="image_ManipulationInertiaStarting">
                        <Image RenderOptions.BitmapScalingMode="NearestNeighbor" IsManipulationEnabled="True"                            
                       x:Name="image" Stretch="Uniform" RenderTransform="{StaticResource ImageTransformResource}"/>
                        <ContentControl.Effect>
                            <DropShadowEffect Opacity="0.6" ShadowDepth="0" BlurRadius="20" />
                        </ContentControl.Effect>
                    </ContentControl>             
                </ScrollViewer>
            </Border>
            <StackPanel Grid.Row="1" Orientation="Horizontal" VerticalAlignment="Center" HorizontalAlignment="Center">
                <StackPanel.Resources>
                    <Style x:Key="buttonStyle" TargetType="Control">
                        <Setter Property="Height" Value="30"/>
                        <Setter Property="Width" Value="96"/>
                        <Setter Property="IsEnabled" Value="False"/>
                    </Style>
                </StackPanel.Resources>

                <local:LabMainButtonControl x:Name="btnPrevious" Margin="0,0,10,0" NormalBackground="{StaticResource previousButtonBackground1}" PressedBackground="{StaticResource previousButtonBackground2}" Style="{StaticResource buttonStyle}" MouseUp="btnPrevious_MouseUp"/>
                <local:LabMainButtonControl x:Name="btnNext" Margin="0,0,10,0" NormalBackground="{StaticResource nextButtonBackground1}" PressedBackground="{StaticResource nextButtonBackground2}" Style="{StaticResource buttonStyle}"  MouseUp="btnNext_MouseUp"/>
                <local:LabMainButtonControl x:Name="btnGoBack" Margin="0,0,0,0" NormalBackground="{StaticResource pdfBackButtonBackground1}" PressedBackground="{StaticResource pdfBackButtonBackground2}" Style="{StaticResource buttonStyle}" MouseUp="btnGoBack_MouseUp"/>
                <local:LabMainButtonControl x:Name="btnZoomIn" Margin="10,0,0,0" NormalBackground="{StaticResource zoomInBackground1}" PressedBackground="{StaticResource zoomInBackground2}" Style="{StaticResource buttonStyle}" MouseUp="btnZoomIn_MouseUp"/>
                <local:LabMainButtonControl x:Name="btnZoomOut" Margin="10,0,0,0" NormalBackground="{StaticResource zoomOutBackground1}" PressedBackground="{StaticResource zoomOutBackground2}" Style="{StaticResource buttonStyle}" MouseUp="btnZoomOut_MouseUp"/>

                <StackPanel  Orientation="Horizontal" Margin="10,0,0,0">
                    <TextBlock Name="label" FontSize="16" VerticalAlignment="Center" Foreground="WhiteSmoke" FontWeight="Medium" Margin="3">转到</TextBlock>
                    <TextBox  IsEnabled="False" Width="100" Height="30" Name="textPage" FontSize="16" VerticalAlignment="Center" PreviewKeyDown="textPage_PreviewKeyDown"></TextBox>
                </StackPanel>

            </StackPanel>
        </Grid>
    </Grid>
</UserControl>
